home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-07 / mail15.zip / AUTOMAIL.ASP < prev    next >
Text File  |  1991-12-19  |  7KB  |  254 lines

  1. ;
  2. ; MAILROOM automatic run script. - Ver. 1.0
  3. ;  copyright 1991 - James A. Littlefield 
  4. ;
  5. ; Script to automatically execute the contents of the batch file mailrm.bat
  6. ; at preset intervals.  The number of seconds between invokes is contained
  7. ; in the INTERVAL constant. This script will run mailrm every interval 
  8. ; seconds and will also run mailrm 1x after each remote login session.
  9. ; If INTERVAL is set to 0 then mailrm will not run periodically.
  10. ;
  11. ; After each remote user, pcmail is run to compress the procomm message data
  12. ; files and eliminate any files that may have been deleted.
  13. ;
  14. ; For proper operation the attached modem/computer must use CD, the procomm
  15. ; host options menu must have the connection type set for MODEM and the
  16. ; Goodbye Action option set for HANGUP.
  17. ;
  18. ; 12/04/91 - Send answer init string to modem on entry to the script
  19. ;            (Whatever is in the AutoAnswer setup option will be sent
  20. ;           - display last user and connect time msg in dialog box
  21. ;           - script will automatically set host mode for modem connection
  22. ;             with hangup on logoff
  23. ; 12/05/91 - send modem init string on program entry
  24. ;          - remove script exit on abort of host mode
  25. ; 12/09/91 - try snatching baud rate after CD is detected
  26. ;           - add code to detect and set modem baud rate messages
  27. ;           - delay entry into host mode until CD is hight for 1 second
  28. ; 12/11/91 - break into subprograms to try to get around disk overlay
  29. ;             problems.
  30. ; 12/13/91 - and setting restore around key processing
  31. ; 12/15/91 - trap all keys, allow only <esc> and <f2>
  32. ;             <esc> = exit script
  33. ;            <f2>  = local login
  34. ;
  35.  
  36. integer INTERVAL=0 
  37. string tvar
  38. string msg1
  39. string msg2
  40. string msg300,msg1200,msg2400,msg4800,msg9600
  41. string ans_on,ans_off
  42. string batchname = "mailroom.bat"
  43. integer next_time            ; next time to run
  44. integer con_tmr=0
  45. long default_baud=1200
  46.  
  47.  
  48. proc main                    ; script main procedure
  49. integer index=0
  50. integer mval=0
  51.  
  52. call init_proc                ; set everything up
  53. while (forever)                ; just do host and run mailrm after each user
  54.  call setup_tmr                ; init scrn display and counter
  55.  while (2>con_tmr)            ; run mailrm every hour
  56.   strcmp tvar $time1
  57.   if not success
  58.     con_tmr++
  59.      tvar=$time1
  60.      atsay 9 36 7 $time1
  61. ;
  62. ; Since the script turns of procomm key checking (for speed)
  63. ; capture and process all the keys that have arrived in the last
  64. ; second
  65. ;
  66.     if (hitkey != 0) 
  67.       call process_keys
  68.     endif
  69.  
  70.     if INTERVAL>0
  71.       dec next_time 
  72.       strfmt msg1 "Next Run in %6d sec." next_time
  73.       if (next_time==0)
  74.            next_time=INTERVAL
  75. ; --------------------------- may cause a long wait before things start up
  76.            dos batchname        ; run mailrm (put proper args in)
  77.       endif
  78.     else
  79.      msg1="Run After Next Remote User"
  80.     endif
  81.      atsay 8 20 7 msg1
  82.  endif
  83.  
  84. ;
  85. ; Make sure CD is high for at least 1 second before going to host
  86. ;
  87.     if (connected ==0)
  88.      con_tmr=0
  89.     endif
  90.  
  91. ;
  92. ; look for a connect type of message as defined in setup menus
  93. ;
  94. while (comdata !=0)
  95.   mval=0 
  96.   while ((mval != 0x0d) && (mval != 0x0a) && (comdata !=0))
  97.    comgetc mval                ; read the keycode
  98.    strpoke msg2 index mval
  99.    index++
  100.    if (index > 39) 
  101.     index=0
  102.    endif
  103.   endwhile
  104.  
  105. if ((mval == 0x0d) || (mval == 0x0a))
  106.   index--
  107.   strpoke msg2 index 0        ; tack a null on the end truncate last char
  108.  
  109.   switch msg2
  110.    case msg300
  111.     set baud 300
  112.     endcase
  113.  
  114.    case msg1200
  115.     set baud 1200
  116.     endcase
  117.  
  118.    case msg2400
  119.     set baud 2400
  120.     endcase
  121.  
  122.    case msg4800
  123.     set baud 4800
  124.     endcase
  125.  
  126.    case msg9600
  127.     set baud 9600
  128.     endcase
  129.  
  130.   endswitch
  131.   statrest
  132.   strset msg2 32 80
  133.   index=0
  134.  endif
  135.  endwhile
  136.  endwhile
  137.  
  138. ;
  139. ; If we got to here then CD must have been active for at least 1 sec.
  140. ; but apparently it is no gone so just hangup and resume waitloop.
  141. ;
  142.  if (connected == 0)
  143.   hangup
  144.   loopwhile
  145.  endif
  146.  call do_host            ; enter host mode
  147. endwhile
  148. endproc
  149.  
  150. ;
  151. ; This procedure sets everyting up.
  152. ;
  153. proc init_proc
  154.  integer mval=0
  155.  integer k=0
  156.  integer index=0
  157.  
  158.  clear
  159.  next_time=INTERVAL
  160.  fetch modem cnct300 msg300
  161. ;
  162. ; remove the (sometimes) trailing ^M on the 300 baud connect string
  163. ;
  164.  strlen msg300 index
  165.  index--
  166.  strpeek msg300 index mval
  167.  index--
  168.  strpeek msg300 index k
  169.  if ((mval == 77) || (k == 94))
  170.   strpoke msg300 index 0
  171.  endif
  172.  fetch modem cnct1200 msg1200
  173.  fetch modem cnct2400 msg2400
  174.  fetch modem cnct4800 msg4800
  175.  fetch modem cnct9600 msg9600
  176.  fetch modem autoansoff ans_off
  177.  fetch modem autoanson ans_on
  178.  fetch baud default_baud
  179.  set host connection modem    ; this is a modem connect so monitor CD
  180.  set host goodbye hangup    ; hangup line when user logs off
  181.  set host autobaud on        ; enable autobaud
  182.  set modem autobaud on        ; enable autobaud
  183.  set display off                ; inhibit echo to the screen
  184.  set switchcase off            ; case insensitive comparison for switch strings
  185.  set keys on                    ; don't check for keys before each line
  186.  set rxdata on                ; script will handle i/o
  187.  termkey 0x2400                ; send modem init comnd - terminates ans. mode
  188. endproc
  189.  
  190. ;
  191. ; Since CD will be high on entry to the host mode the proper baud rate
  192. ; must be set prior to entry.  This function will enter host mode and
  193. ; when the remote user logs off, will execute the contents of the batch
  194. ; file whose name is contained in the string variable batchname
  195. ;
  196. proc do_host
  197.  clear
  198.  set display on                ; enable screen display
  199.  host                        ; execute the host command 
  200.  set display off            ; inhibit screen display
  201.  dos batchname                ; put all the necessary command in here
  202.  next_time=INTERVAL
  203.  set baud default_baud        ; restore default baud rate
  204.  statrest                    ; redisplay status line
  205. endproc
  206.  
  207. proc setup_tmr
  208.  box 5 18 15 60 7
  209.  atsay 6 20 7  "MAILRM Automatic Run Script"
  210.  atsay 9 20 7  "Current time "
  211.  atsay 11 20 7 "   Last User:"
  212.  atsay 11 36 7 $H_NAME
  213.  atsay 12 20 7 "Connected At:"
  214.  atsay 12 36 7 $H_ONLINE
  215.  atsay 13 20 7 "Session Time:" 
  216.  atsay 13 36 7 $H_ELAPSED
  217.  tvar=$time0
  218.  transmit ans_on             ; send autoans enable to the modem 
  219.  strset msg2 32 80
  220.  con_tmr=0
  221. endproc
  222.  
  223. ;
  224. ; Process keys until none are left
  225. ;
  226. proc process_keys
  227. integer a
  228.  while (hitkey !=0)
  229.   keyget a
  230.   switch a
  231.   case 0x001b
  232.     clear
  233.     box 11 19 13 58 7
  234.     atsay 12 20 5 "Terminating Automatic Execution Script"
  235.     alarm 2
  236.     transmit ans_off        
  237.     clear
  238.     exit                    ; terminate the script
  239.       endcase
  240.  
  241.   case 0x3c00                ; establish local login session
  242.      vidsave 0
  243.      set keys off
  244.      call do_host            ; start host mode session
  245.      set keys on
  246.      vidrest 0
  247.      transmit ans_on
  248.       endcase
  249.   endswitch
  250.  endwhile
  251.  set baud default_baud
  252.  statrest                    ; redisplay status line
  253. endproc
  254.